package com.aspects;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class DbDmlAspect {
    @Before("execution(* com.dao.impl.*.*(*))")
    public void dobefore(JoinPoint jp) {

        System.out.println("**************");
        System.out.println("方法执行前：" + jp.getSignature());
        System.out.println(jp.getArgs()[0]);
       // System.out.println("方法执行后：" + jp.getSignature());

    }
    @AfterReturning(pointcut = "execution(* com.dao.impl.*.*(*))",returning = "ret")
    public void doAfterReturning(JoinPoint jp,Object ret) {
        System.out.println("**************");
        System.out.println("方法执行后：" + jp.getSignature());
        System.out.println("返回值：" + ret);
    }
    @AfterThrowing(pointcut = "execution(* com.dao.impl.*.*(*))",throwing = "ex")
    public void doAfterThrowing(JoinPoint jp,Throwable ex) {
        System.out.println("**************");
        System.out.println("方法执行异常：" + jp.getSignature());
        System.out.println("异常信息：" + ex);

    }
    @After("execution(* com.dao.impl.*.*(*))")
    public void doAfter(JoinPoint jp) {
        System.out.println("**************");
        System.out.println("方法执行完成：" + jp.getSignature());
    }
    @Around("execution(* com.dao.impl.*.*(*))")
    public Object doAround(ProceedingJoinPoint jp) throws Throwable {
        try {
            System.out.println("**************");
            System.out.println("方法执行前：" + jp.getSignature());
            Object ret = jp.proceed();
            System.out.println("方法执行后：" + jp.getSignature());
            System.out.println("返回值：" + ret);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }


    }
}
